﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Text;
using nl.tno.ict.multitouch.wpfmultitouch.events;
using System.Windows;
using System.Timers;
using System.IO;
using System.Windows.Input;
using System.ComponentModel;

namespace nl.tno.ict.multitouch.wpfmultitouch.controls
{
    public class MTRadioButton : RadioButton, INotifyPropertyChanged, MTObject
    {
        /// <summary>
        /// Timeout in miliseconds
        /// </summary>
        private int _timeout = 1000;
        /// <summary>
        /// When a finger has not moved for a specified, use timeout, time this event will be thrown
        /// </summary>
        public event NotMovedEventArgs NotMoved;
        private int _fingerCount;

        public MTRadioButton()
        {
            //Sets the TouchEnabledObjectProperty for the element always true.
            MTProperties.SetTouchEnabled(this, true);
            this.Click += new RoutedEventHandler(MTRadioButton_Click);
        }

        private void MTRadioButton_Click(object sender, RoutedEventArgs e)
        {
            MouseEventArgs mea = new MouseEventArgs(Mouse.PrimaryDevice,1); 
            mea.RoutedEvent = MTRadioButton.CheckedEvent;
            this.IsChecked = true;
            if (this.IsChecked == true)
            {
                mea.RoutedEvent = MTRadioButton.CheckedEvent;
            }
            else
            {
                mea.RoutedEvent = MTRadioButton.UncheckedEvent;
            }
            this.RaiseEvent(mea);
            e.Handled = true;
        }

        /// <summary>
        /// Gets or sets a bool that describes the value of a CanBeScaledObjectProperty for the element.
        /// </summary>
        public bool CanBeScaled { get { return MTProperties.GetCanBeScaled(this); } set { MTProperties.SetCanBeScaled(this, value); } }
        /// <summary>
        /// Gets or sets a bool that describes the value of a CanBeDraggedObjectProperty for the element.
        /// </summary>
        public bool CanBeDragged { get { return MTProperties.GetCanBeDragged(this); } set { MTProperties.SetCanBeDragged(this, value); } }
        /// <summary>
        /// Gets or sets a bool that describes the value of a CanBeClickedObjectProperty for the element.
        /// </summary>
        public bool CanBeClicked { get { return MTProperties.GetCanBeClicked(this); } set { MTProperties.SetCanBeClicked(this, value); } }
        /// <summary>
        /// Gets or sets a bool that describes the value of a CanBeRotatedObjectProperty for the element.
        /// </summary>
        public bool CanBeRotated { get { return MTProperties.GetCanBeRotated(this); } set { MTProperties.SetCanBeRotated(this, value); } }
        /// <summary>
        /// Gets or sets a bool that describes the value of a AdornersEnabledProperty for the element.
        /// </summary>
        public bool AdornersEnabled { get { return MTProperties.GetAdornersEnabled(this); } set { MTProperties.SetAdornersEnabled(this, value); } }

      

        public bool IsDragging
        {
            get { return MTProperties.GetIsDragging(this); }
            set
            {
                MTProperties.SetIsDragging(this, value);
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsDragging"));
            }
        }

        public bool IsScaling
        {
            get { return MTProperties.GetIsScaling(this); }
            set
            {
                MTProperties.SetIsScaling(this, value);
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsDragging"));
            }
        }

        public bool IsRotating
        {
            get { return MTProperties.GetIsRotating(this); }
            set
            {
                MTProperties.SetIsRotating(this, value);
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsRotating"));
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region MTObject Members

        /// <summary>
        /// Gets or sets the timeout, in ms, used to by the NotMoved event. Default: 1000 ms
        /// </summary>
        public int Timeout
        {
            get { return _timeout; }
            set { _timeout = value; }
        }

        void MTObject.NotMoved()
        {
            if (NotMoved != null)
                NotMoved(this, new EventArgs());
        }

        public int FingerCount
        {
            get
            {
                return _fingerCount;
            }
            set
            {
                _fingerCount = value;
            }
        }

        /// <summary>
        /// Gets or sets the onTop dependency property. When true, when a finger touches the object the object
        /// gets on top of the screen (z-index changes).
        /// </summary>
        public bool OnTop
        {
            get { return MTProperties.GetOnTop(this); }
            set { MTProperties.SetOnTop(this, value); }
        }

        /// <summary>
        /// Set the object TouchEnabled. When an object isn't touchEnabled interaction with fingers is not
        /// possible (nothing will happen).
        /// </summary>
        public bool TouchEnabled
        {
            get { return MTProperties.GetTouchEnabled(this); }
            set { MTProperties.SetTouchEnabled(this, value); }
        }

        #endregion
    }
}
